﻿using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using ReflectionStudio.Core.Events;
using System.Collections;
using System.Collections.Generic;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for ProductionOrder.xaml
    /// </summary>
    public partial class TGB04 
    {

        

        public TGB04()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VGPDAT();
            MESSAGES += "QCRELOAD;REFRESHBYGB33;LOADGP;";
            this.DataContext = MV;
            InitializeComponent();
            IsEdit = false;
        }
        /// <summary> 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
       
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e); 
           if(dwMaster==null)
            {
                KEY = "";
            }
           else
            {
                KEY = TMV.GPPARTIE+TMV.GPPARTIEKZ;
            }
        }

        public override void OnARTChg(string des)
        {
            base.OnARTChg(des);
        }
        public override void NewCommand(object sender, System.Windows.RoutedEventArgs e)
        {
            if (!IsNew)
            {
                IsNew = true;
                MU = "";
                ART = "";
                BOX = 0;
                QTY = 0.0;
                return;
            }

            this.Focus();
            if(MU.Length==0)
            {
                MessageBox.Show("请选择包装方式");
                return;
            }
            if (BOX== 0)
            {
                MessageBox.Show("请输入箱子数");
                return;
            }
            if (QTY == 0)
            {
                MessageBox.Show("清输入总重量");
                return;
            }
            if (ART.Length == 0)
            {
                MessageBox.Show("请选择纱线");
                return;
            }
            PM["CART"] = ART.Substring(0,23);
            PM["CFARBE"] = ART.Substring(23, 10); ;
            PM["BOX"] = BOX;
            PM["QTY"] = QTY*0.01;
            PM["LO"] = LO;
            PM["LB"] = LB;
            PM["LP"] = LP;
            PM["MU"] = MU;
            PM["ORDERNUM"] = "  000000000 ".PadRight(12);
            TMV.NEWGB04(PM); 
            vwMaster.View.MoveCurrentToFirst();
            IsNew = false;
            MU = "";
            ART = ""; 
            base.NewCommand(sender, e);
        }

        public override void DeleteCommand(object sender, System.Windows.RoutedEventArgs e)
        {
            if (dwMaster == null)
                return;
            
            TMV.DGP01(dwMaster);
            filter = "GPPARTIE='" + dwMaster["GPPARTIE"].ToString() + "'";
            vwMaster.View.MoveCurrentTo(-1);
            rows = TBMain.Select(filter);
            foreach (DataRow row in rows)
            {
                row.Delete();
            }
            TBMain.AcceptChanges();
            base.DeleteCommand(sender, e);
        }
        public override void SaveCommand(object sender, System.Windows.RoutedEventArgs e)
        {
            try
            {
                /*
                PM["ORDERNUM"] = EXAUF;
                PM["AUFTYP"] = "B";
                PM[""] = TMV.RWAUF;
                PM["KRS"] = KRS;
                PM["LFD"] = LFD;
                PM["POS"] = POS;
                PM["TBWB14"] = TBMain;
                TMV.POSTBATCH(PM);
                //TMV.VEKP.UpdateEKPOS(dwEKP, 15);
                TMV.VEKP.UpdateEKPOS(dwEKP, 12);

                string key = EXAUF;
                EXAUF = "";
                EXAUF = "B" + KRS + LFD + POS;
                /*  key = RWAUF;
                RWAUF = "";
                RWAUF = key;*/
                INFO = "已保存";
                base.SaveCommand(sender, e);
               
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        private void QTY_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key != System.Windows.Input.Key.Enter)
                return;
            if (e.Key != System.Windows.Input.Key.Return)
                return;
            NewCommand(sender, e);
        }
    }
}
